<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../css/page2.css">

</head>



<body>
<div class="header">
  <h3>学习论坛</h3>
  <a class="issue"></a>
</div>
    <div id="navBar"></div>
    <div class="Search">
      <input type="text" name="" value=""><button type="button" name="button" onclick="Search()">搜索</button>
    </div>
    <div class="publicMsg"></div>
    <div class="searchMsg"></div>
</body>

<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../../script/main.js"></script>




<script>
var flag=$api.getStorage('flag');
var contenturl;
var items=[];
var type=0;
var page=0;
var size=8;

    apiready = function() {
      $(".issue").click(function(){
          api.openWin({
              name: 'page1',
              url: 'issue.html',
              pageParam: {
                  name: 'test'
              }
          });

      })
      var NVNavigationBar = api.require('NVNavigationBar');
      var navBar = $("#navBar")[0];
        getNav();
        getContent(type,page,size);
        function getNav() {
            var Url = '/api/pa-project-types';
            var functionRet=function(ret1){
            var items= [{
                  title: '论坛首页',
                  bg: '#1296db',
                  bgSelected: '#1296db'
              }];
                for (var i = 0; i < ret1.length; i++) {

                    items.push({
                      title: ret1[i].name,
                      bg: '#1296db',
                      bgSelected: ' #1296db'
                    });
                      }
                NVNavigationBar.open({
                    rect: {
                        x: 0,
                        y: api.frameHeight/10,
                        w: api.frameWidth,
                        h: 30
                    },
                    styles: {
                      orientation: 'horizontal',
                      bg: '#6b6b6b',
                    bgAlpha: 1,
                     font: {
                    size: 14,
                    sizeSelected: 14,
                    color: '#ccccff',
                     colorSelected: '#FFFFFF',
                      alpha: 1
                        },
                        itemSize: {
                            w: api.frameWidth/4,
                            h: 44
                        }
                    },
                    items: items,
                    selectedIndex: 0,
                    fixedOn: api.frameName,
                    fixed: true,
                    id: 'first'
                }, function(ret, err) {
                          if (ret.eventType=="click") {
                               console.log(JSON.stringify(ret));
                                $(".publicMsg").empty();

                                getContent(ret.index,page,size);
                                // type=ret.index;
                          }

                    //api.alert({msg:JSON.stringify(ret)});
                });


}
        var functionErr = function(err1) {
            return false
        }

        get(Url, functionRet, functionErr);
    }

  function getContent(type,page,size){
    $("input").focus(function(){
        $(".Search").css("top","20%")
    })
    $("input").blur(function(){
        $(".Search").css("top","14%")
    })
     if (type==0) {
        contenturl='/api/public-msgs/top-list?page='+page+'&size='+size;
     }else {
      type--;
      contenturl='/api/public-msgs/top-list?type='+type+'&page='+page+'&size='+size;
      }
      var functionRet=function(ret1){
             if (ret1.length) {
                     for (var i = 0; i < ret1.length; i++) {
                       console.log(11111);
                       var imageSrc=ret1[i].imageList;
                       $(".publicMsg").append('<div class="showModule" showModule-id='+ret1[i].id+'><div class="headerImage"><img src='+ret1[i].userHeaderImageUrl+'><span>'+ret1[i].userName+'</span><span class="delete" style="color:red;" delete-id='+ret1[i].id+'>删除</span></div><div class="At" At-id='+ret1[i].id+'><h3 class="showModule_t">'+ret1[i].title+'</h3><span class="createTime">发表时间:'+ret1[i].createTime+'</span><div class="article">'+ret1[i].content+'</div><div class="Image"><img src='+"http://"+imageSrc[0].replace(/["'"]/g,"")+'></div></div></div>');
                     }
             }

                  $(".At").click(function(){
                    console.log($(this).attr("At-id"));
                    api.openWin({
                        name: 'detail',
                        url: './detail.html',
                        pageParam: {
                            id:$(this).attr("At-id")
                        }
                    });

                  });
                  if(flag!=7){
                    $(".delete").css("display","none");
                  }

  }
  var functionErr=function(err){
    return false
  }
   get(contenturl,functionRet,functionErr);

    }

  }
  function Search(){

        var text=$(".Search input").val();
        var Searchurl='/api/public-msgs/search?key='+text;
         console.log(text);
         var functionRet=function(ret){
                  if (ret.length) {
                  console.log(ret.length);
                    for (var i = 0; i < ret.length; i++) {
                      var imageSrc=ret[i].imageList;
                      $(".publicMsg").hide();
                      $(".searchMsg").append('<div class="showModule" showModule-id='+ret[i].id+'><div class="headerImage"><img src='+ret[i].userHeaderImageUrl+'><span>'+ret[i].userName+'</span><span class="delete" style="color:red;" delete-id='+ret[i].id+'>删除</span></div><div class="At" At-id='+ret[i].id+'><h3 class="showModule_t">'+ret[i].title+'</h3><span class="createTime">发表时间:'+ret[i].createTime+'</span><div class="article">'+ret[i].content+'</div><div class="Image"><img src='+"http://"+imageSrc[0].replace(/["'"]/g,"")+'></div></div></div>');
                    }

                  }
                  else {
                     api.alert({
                         title: '提示',
                         msg: '没有找到相关信息！',
                     }, function(ret, err){
                         if( ret ){
                            //alert( JSON.stringify( ret ) );
                         }else{
                              alert( JSON.stringify( err ) );
                         }
                     });

                  }
         }
         var functionErr=function(){
              return false
         }
           get(Searchurl,functionRet,functionErr);

  }

</script>

</html>
